function getAllJson(jsons) {
    let tmpitem=[]
    for (let item of jsons) {
        let tmparr={}
        tmparr["value"]=item["code"];
        tmparr["name"]=item["name"];
        if (item["code"] === user.code) {
            tmparr["selected"] = true;
        }
        if(item["users"]){
            for(let it of item["users"]){
                item["list"].push(it)
            }
        }
        if(item["list"] && item["list"].length){
            tmparr["children"]=   this.getAllJson(item["list"]);
            tmpitem.push(tmparr)
        }else{
            tmpitem.push(tmparr)
        }

    }
    return tmpitem
}

function getxmselect(el,name, data) {
    return xmSelect.render({
        el: el,
        name: name,

        tree: {
            show: true,
            showLine: true,
            showFolderIcon:true,
            indent: 20,
            expandedKeys:false
        },
        height: 'auto',
        data: data,
        on: function ({ arr, change, isAdd }) {
            return this
        }
    })
}

let layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,
    $ = layui.jquery,
    laydate = layui.laydate, isPurchaseAdmin = false;
    //采购方式 默认为无
    let isProcurementMethod = true;

//采购方式标签 有该标签:false 无该标签:true
isProcurementMethod = getAllRolesByCurr("ProcurementMethod");

let operationList=[];
let salesmanCodeList=[];
let deptOperationList=[];
let deptSalesmanList=[];
(function () {
    let treeList = getCurrentDepartmentUser();
    if(treeList && treeList.list){
        let userTree = getAllJson(treeList.list);
        operationList=getxmselect("#executorCode","executor",userTree)
        salesmanCodeList=getxmselect("#salesmanCode", "salesman", userTree);
    }else{
        operationList=getxmselect("#executorCode","executor",[{name: user.name, value: user.code}])
        salesmanCodeList=getxmselect("#salesmanCode", "salesman", [{name: user.name, value: user.code}])
    }

    //获取当前用户所属部门树()
    let currentDeptTreeList = getAllUserDepartmentTree();
    if (currentDeptTreeList && currentDeptTreeList.list) {
        let deptTree = getAllJson(currentDeptTreeList.list);
        deptOperationList = getxmselect("#deptOperationCode", "deptOperationCode", deptTree);
        deptSalesmanList = getxmselect("#deptSalesmanCode", "deptSalesmanCode", deptTree);
    } else {
        deptOperationList = getxmselect("#deptOperationCode", "deptOperationCode", [{name: user.name, value: user.code}]);
        deptSalesmanList = getxmselect("#deptSalesmanCode", "deptSalesmanCode", [{name: user.name, value: user.code}]);
    }

})()

let loginUserCode = user.code;//当前登录用户编码
let isMsn="否";
//签约单位
let complaintUnit = [];
//判断角色是否包含 研发助理 研发主管
let isNotResearchAndDevelopment=false;
isNotResearchAndDevelopmentF();

let startDeliverTime= laydate.render({
    elem: '#startDeliverTime',//选择器结束时间
    type: 'date',
    min:"1970-1-1",//设置min默认最小值
    done: function(value,date){
        startDeliverTime.config.max={
            year:date.year,
            month:date.month-1,
            date: date.date,
            hours: 0,
            minutes: 0,
            seconds : 0
        }
    }
});

let endDeliverTime=laydate.render({
    elem: '#endDeliverTime',
    type: 'date',
    max:"2099-12-31",//设置一个默认最大值
    done: function(value, date){
        endDeliverTime.config.min ={
            year:date.year,
            month:date.month-1,
            date: date.date,
            hours: 0,
            minutes: 0,
            seconds : 0
        };
    }
});

let startSignTime=laydate.render({
    elem: '#startSignTime',
    type: 'date',
    max:"2099-12-31",//设置一个默认最大值
    done: function(value, date){
        endSignTime.config.min ={
            year:date.year,
            month:date.month-1,
            date: date.date,
            hours: 0,
            minutes: 0,
            seconds : 0
        };
    }
});
let endSignTime= laydate.render({
    elem: '#endSignTime',//选择器结束时间
    type: 'date',
    min:"1970-1-1",//设置min默认最小值
    done: function(value,date){
        startSignTime.config.max={
            year:date.year,
            month:date.month-1,
            date: date.date,
            hours: 0,
            minutes: 0,
            seconds : 0
        }
    }
});


let paymentTypeList = getdictionary(5, 17);//付款类型
let currencyList = getdictionary(5,14);//币种

let userList;


//操作员、业务员
$.ajax({
    type : 'POST',
    url:'user/getAllUserNameAndCode',
    dataType:"json",
    contentType: 'application/json;charset=utf-8',
    success:function(res){
        if(res.status == 200){
            if(res.data){
                userList = res.data;
                form.render('select');
            }else{
                layer.msg(res.msg,{icon:0});
            }
        }else{
            layer.msg(res.msg,{icon:4});
        }
    }
});

form.render('select');


layui.use(['dropdown'], function () {
    let dropdown = layui.dropdown;
    dropdown.onFilter("statistics", function (event) {
        switch (event) {
            case "s1":
                parent.intab("views/jsp/ExportBusiness/tpl/purchaseStatistics1.jsp", "采购产品情况一览统计")
                break
            case "s2":
                parent.intab("views/jsp/Money/tpl/paymentStatistics1.jsp","付款情况统计")
                break
            case "s3":
                parent.intab("views/jsp/Money/tpl/paymentStatistics2.jsp","采购预付款统计")
                break
            case "s4":
                parent.intab("views/jsp/ExportBusiness/tpl/purchaseStatistics2.jsp","采购排产及计划统计")
                break
            case "s5":
                parent.intab("views/jsp/ExportBusiness/tpl/purchaseOrderRestock.jsp","补货采购订单")
                break
            case "s6":
                parent.intab("views/jsp/ExportBusiness/tpl/purchaseProductIntegration.jsp","采购产品整合")
                break
            case "s7":
                parent.intab("views/jsp/ExportBusiness/tpl/purchaseSampleStatistics.jsp","样品采购付款详情")
                break
        }
    });
})

//判断当前用户是否是：采购主管、管理员、产品中心、财务
function getIsPurchaseAdmin() {
    $.ajax({
        url: 'customer/isPurchaseAdmin',
        async: false,
        success: function (da) {
            if (da.status == 200) {
                isPurchaseAdmin = da.data;
            }
        }
    });
}

layer.ready(function () {
    //判断当前用户是否是：采购主管、管理员、产品中心、财务
    getIsPurchaseAdmin();

    $.ajax({
        url: 'billChange/isMsn',
        type: 'GET',
        async: false, // 同步
        success: function (date) {
            isMsn=date.data
        }
    })

    $.ajax({
        url: "company/getAllMakerUnit",
        async:false,
        success: function (res) {
            if (res.status == 200) {
                complaintUnit = res.data;
                //制单公司
                $.each(complaintUnit, function (index, item) {
                    if(item){
                        $("#complaintUnit").append(new Option(item.name, item.code));
                    }
                });
                form.render('select');
            } else {
                layer.msg(res.msg, {icon: 5});
            }
        }
    });


table.render({
    elem: '#procurementselect'
    ,id: 'procurementtableid'
    ,url: 'purchase/selectPurchaseList'
    ,method:'post'
    ,contentType: 'application/json;charset=utf-8'
    ,request: {
        pageName: 'pageNum'
        ,limitName: 'pageSize'
    }
    ,where: {executor: user.code,salesman: user.code}
    ,toolbar: '#procurementtoolbar'
    ,totalRow: true
    ,cols: [[
        {checkbox: true, fixed: true},
        {field: 'numbers',width: 50,type:'numbers',title:'序号', totalRowText: '合计'}
        ,{field: 'purchaseOrderNo', width: 120, title: '采购单号',event: "purchaseorderno", sort: true}
        ,{field: 'purchaseType', width: 80, title: '类型', templet: function(d) {
                let purchaseType = d.purchaseType;
                let name = "";
                switch (purchaseType) {
                    case "1":
                        name = "成品";
                        break;
                    case "2":
                        name = "配件";
                        break;
                    case "3":
                        name = "备货";
                        break;
                    case "4":
                        name = "销售";
                        break;
                    case "5":
                        name = "样品";
                        break;
                    default:
                        name = "待定";
                        break;
                }
                return name;
            }
        }
        ,{field: 'supplierName', title:'供应商名称',width:120,style:"overflow:hidden",
        }
        ,{field:'paymentType', title:'付款类型',width: 100,
            templet: function(data) {
                let name = "";
                $.each(paymentTypeList, function(index, item) {
                    if (data.paymentType==item.code){
                        name = item.name;
                        return ;
                    }
                });
                return name;
            }
        }
        ,{field:'companyName', title:'签约单位',width: 120,style:"overflow:hidden",
        }
        ,{field:'signTime', title:'签约日期',width: 120, templet: function(d) {return layui.util.toDateString(d.signTime,"yyyy-MM-dd");}, sort: true }
        ,{field:'deliverDate', title:'交货日期',width: 120, templet: function(d) {return layui.util.toDateString(d.deliverDate,"yyyy-MM-dd");}, sort: true }
        ,{field:'deliverAddress', title:'交货地点',width: 120,style:"overflow:hidden"}
        ,{field:'currency', title:'币种',width: 120,
            templet: function(data) {
                let name = "";
                $.each(currencyList, function(index, item) {
                    if (data.currency==item.code){
                        name = item.name;
                        return ;
                    }
                });
                return name;
            }}
        ,{field:'purchaseTotalPrice', title:'采购总额',width: 120, sort: true, totalRow: true}
        ,{field:'purchaseTotalPriceRMB', title:'RMB采购总额',width: 120, sort: true, totalRow: true}
        ,{field:'executorCode', title:'操作员',width:120,
            templet: function(data) {
                let name = "";
                $.each(userList, function(index, item) {
                    if (data.executorCode==item.code){
                        name = item.name;
                        return ;
                    }
                });
                return name;
            }
        }
        ,{field:'salesmanCode', title:'业务员',width:120,
            templet: function(data) {
                let name = "";
                $.each(userList, function(index, item) {
                    if (data.salesmanCode==item.code){
                        name = item.name;
                        return ;
                    }
                });
                return name;
            }
        }
        ,{field:'fileSum', title:'附件', width: 100, sort: true}
        ,{field:'purchaseFeedbackDesc', title:'备注', width: 150, sort: true}
        ,{field:'paymentTime', title:'供应商账期',width: 120}
        ,{field:'earnestRate', title:'定金比例',width: 120}
        ,{field:'earnestMoney', title:'定金金额',width: 120}
        ,{field:'invoiceStatus', title:'是否开票',width: 120, templet: function(d) {return d.invoiceStatus==1?"是":"否";}}
        ,{field:'materialSupplier', title:'素材供应商',width: 120}
        ,{field:'taxIncluded', title:'是否含税',width: 120,
            templet: function(d) {
                switch (d.taxIncluded) {
                    case "1": return "含税出厂价";
                    case "2": return "未税出厂价";
                    case "3": return "含税FOB价";
                    case "4": return "未税FOB价";
                }
            }
        }
        ,{field:'salesContractNo', title:'销售合同号',width: 120,style:"overflow:hidden"}
        ,{field:'boxStatus', title:'单据类型',width:100,
            templet: function(data) {
                switch (data.boxStatus) {
                    case "1": return "草稿箱";
                    case "2": return "待批箱";
                    case "2.1": return "待批箱";
                    case "3": return "已批箱";
                    case "4": return "完成箱";
                    case "5": return "垃圾箱";
                    case "6": return "终止箱";
                }
            }}
        ,{fixed: 'right', width:240, title:'操作',templet: function(d){
                // 单据状态/类型（1：草稿箱，2：待批箱，3：已批箱，4：完成箱，5垃圾箱）
                var html="<div>"
                if(isMsn=="是"){//普通管理员
                    if(d.boxStatus==2.1 && (user.code=="RKB010" || user.code=="RKB012") ){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"through\">审批通过</a>"
                    }
                    if(d.boxStatus==2.1 &&user.code!="RKB010" && user.code!="RKB012"){
                        html=html+"<a style='background-color: red;' class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"xxx\">等待上级审批</a>";
                    }
                    if(d.boxStatus==1 || d.boxStatus==2){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"update\">修改</a>";
                    }
                    if(d.boxStatus==1){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"submits\">提交审批</a>" +
                            "<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"delect\">删除</a>"
                    }
                    if(d.boxStatus==2){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"through\">审批通过</a>"
                    }
                    if(d.boxStatus==2 || d.boxStatus==2.1){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"backtothe\">审批退回</a>"
                    }
                    if(d.boxStatus == 3 && user.code === "RKB037"){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"backtothe\">审批退回</a>"
                    }
                    if(d.boxStatus==3){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"update\">修改</a>" +
                        "<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"complete\">完成</a>"
                    }
                    if(d.boxStatus==3){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"termination\">终止</a>"
                    }
                    if(d.boxStatus==6){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"terminationBack\">取消终止</a>"
                    }
                    return html+"</div>";
                }else{
                    if(d.boxStatus==2||d.boxStatus==2.1){
                        html=html+"<a style='background-color:red;' class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"xxx\">等待上级审批</a>";
                    }
                    if (d.boxStatus == 1 || d.boxStatus == 2 || d.boxStatus == 2.1) {
                        html = html + "<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"update\">修改</a>"
                    }
                    if(d.boxStatus == 1){
                        html = html   +
                            "<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"submits\">提交审批</a>" +
                        "<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"delect\">删除</a>"
                    }
                    if(d.boxStatus==3){
                        html=html+"<a class=\"layui-btn layui-btn-sm layui-btn-normal\" lay-event=\"complete\">完成</a>"
                    }
                    return html + "</div>";
                }
            }
        }
    ]]
    ,height: $(document).height() - $('#procurementselect').offset().top - 50
    ,page: true
    ,limits: [10,30,50,100,200,300,500,1000]
});

});
document.getElementById('clear').onclick = function(){
    operationList.setValue([ ]);
    salesmanCodeList.setValue([ ]);
    deptOperationList.setValue([ ]);
    deptSalesmanList.setValue([ ]);
};
let purchaseBpmId = '';
let purchaseBpmStatus = '0';//审批状态  0 未审核 1 审批中 2审核完成

//获取已做计划数量
function getPlanCountByPurchaseNo(purchaseNo){
    let count = 0;
    $.ajax({
        url: "exportContract/getPlanCountByPurchaseNo?purchaseNo=" + purchaseNo,
        async: false,
        success: function (res) {
            if (res.status == 200) {
                //出运计划调用 0:未被调用
                count = res.data;
            } else {
                layer.msg(res.msg, {icon: 5});
            }
        }
    });
    return count;
}

//获取采购样品已做样品登记数量
function getResourceSampleCountByPurchaseNo(purchaseNo){
    let count = 0;
    $.ajax({
        url: "resourceSamples/getResourceSampleCountByPurchaseNo?purchaseNo=" + purchaseNo,
        async: false,
        success: function (res) {
            if (res.status == 200) {
                //資源樣品调用 0:未被调用
                count = res.data;
            } else {
                layer.msg(res.msg, {icon: 5});
            }
        }
    });
    return count;
}

//获取采购样品已付款数量
function getResourceSamplePaymentCountByPurchaseNo(purchaseNo){
    let count = 0;
    $.ajax({
        url: "payment/getResourceSampleCountByPurchaseNo?purchaseNo=" + purchaseNo,
        async: false,
        success: function (res) {
            if (res.status == 200) {
                //付款调用 0:未被调用
                count = res.data;
            } else {
                layer.msg(res.msg, {icon: 5});
            }
        }
    });
    return count;
}

table.on('tool(procurementtable)', function(obj){
    let data = obj.data;
    let purchaseNo = data.purchaseOrderNo;
    //审批流判断
    let spFlag = false;
    let spr = {};

    if (obj.event === 'update') {
        //获取已做计划数量
        let count = getPlanCountByPurchaseNo(purchaseNo);
        if (count) {
            layer.msg("已做出运计划，无法修改", {icon: 5});
        } else if(data.purchaseType === "5"){
            let sampleSum = getResourceSampleCountByPurchaseNo(purchaseNo);
            let paymentSum = getResourceSamplePaymentCountByPurchaseNo(purchaseNo);
            if (sampleSum) {
                layer.msg("已做样品登记，无法修改", {icon: 5});
            } else if(paymentSum){
                layer.msg("已做付款，无法修改", {icon: 5});
            }else {
                parent.intab("views/jsp/ExportBusiness/tpl/newSamplePurchase.jsp?id=" + obj.data.id + "&types=" + obj.data.purchaseType, "修改样品采购")
            }
        } else {
            parent.intab("views/jsp/ExportBusiness/tpl/newupprocurement.jsp?id=" + obj.data.id + "&types=" + obj.data.purchaseType, "修改采购")
        }
    } else if (obj.event === 'delect') {
        layer.confirm('确定删除吗', function (index) {
            if(deleteById(data.id)){
                obj.del();
                layer.close(index);
            }
        });
        return;
    }else if(obj.event === 'submits'){
        layer.confirm('确定提交审批吗', function (index) {
            // purchaseBpmId=startPurchaseProcess(data.id);
            if(isMsn=="是"){
                update(data.id,data.boxStatus*1+2,"审批通过");
            }else{
                if (user.departmentCode.indexOf("YFB")!=-1){//如果是技术部提交到技术部
                    update(data.id,data.boxStatus*1+1.1,"提交审批");
                }else {
                    update(data.id,data.boxStatus*1+1,"提交审批");
                }
            }
        });
    }else if(obj.event === 'through'){
        layer.confirm('确定审批通过吗', function (index) {
            if(data.boxStatus*1==2){
                if(isMsn=="是"){
                    update(data.id,data.boxStatus*1+1,"审批通过");
                }
            }else{
                if(user.code=="RKB010"||user.code=="RKB012"){
                    update(data.id,data.boxStatus*1+0.9,"审批通过");
                }
            }
        });
    }else if(obj.event === 'backtothe'){
        //获取已做计划数量
        let count = getPlanCountByPurchaseNo(purchaseNo);
        if (count) {
            layer.msg("已做出运计划，无法退回", {icon: 5});
        } else {
            if(data.purchaseType === "5"){
                let sampleSum = getResourceSampleCountByPurchaseNo(purchaseNo);
                let paymentSum = getResourceSamplePaymentCountByPurchaseNo(purchaseNo);
                if (sampleSum) {
                    layer.msg("已做样品登记，无法退回", {icon: 5});
                }else if(paymentSum){
                    layer.msg("已做付款，无法退回", {icon: 5});
                }
            }
            layer.confirm('确定审批退回吗', function (index) {
                if (data.boxStatus * 1 == 2.1) {
                    update(data.id, 1, "审批退回");
                } else {
                    if (isMsn == "是1") {
                        update(data.id, data.boxStatus * 1 - 0.9, "审批退回");
                    } else {
                        update(data.id, data.boxStatus * 1 - 1, "审批退回");
                    }
                }
            });
        }
    }else if(obj.event === 'complete'){
        layer.confirm('确定完成吗', function (index) {
            update(data.id,data.boxStatus*1+1,"审批完成");
        });
    }else if(obj.event === 'termination'){
        layer.open({
            type: 1,
            title: "确定终止吗?",
            area: ['500px', '300px'],
            content: $("#remarkDiv")//引用的弹出层的页面层的方式加载修改界面表单
        });
        $("#remark").val(data.remark);
        $("#idHidden").val(data.id);
        // layer.confirm('确定终止吗', confirmInfo(3, 5), function (index) {
        //     update(data.id, 6, "终止");
        // });
    }else if(obj.event === 'terminationBack'){
        layer.confirm('确定取消终止吗', confirmInfo(3, 5), function (index) {
            update(data.id, 3, "取消终止");
        });
    }else if(obj.event === 'reduction'){

    }else if (obj.event === "purchaseorderno"){
        parent.intab("views/jsp/ExportBusiness/tpl/viewprocurement.jsp?id="+obj.data.id+"&types="+obj.data.purchaseType,"采购明细")
    }
});

//监听提交,终止
form.on('submit(remarkSubmit)', function(data){
    updateRemark(data.field.idHidden, 6, "终止",data.field.remark);
    return false;
});

//监听提交,终止
form.on('submit(shutDown)', function(data){
    layer.closeAll();
    return false;
});

form.on('submit(submitform)', function(data){
    table.reload('procurementtableid',{where: data.field });
    return false;
});

table.on('toolbar(procurementtable)', function(obj){
    let checkStatus = table.checkStatus(obj.config.id);
    if(checkStatus && checkStatus.data[0]){
        let url = {}
        $.ajax({
            type: 'POST',
            url: 'purchase/selectImgUrlById/'+checkStatus.data[0].id,
            dataType: "json",
            contentType: 'application/json;charset=utf-8',
            async: false,
            success: function (res) {
                if (res.status == 200) {
                    if(res.data){
                        console.log(res.data);
                        // onLine2(url)
                    }else{
                        layer.msg("暂未查询到采购单公司logo和公章",{icon: 4});
                    }
                }else{
                    layer.msg("查询图片失败",{icon: 2});
                }
            },
            error: function (data) {
                layer.msg("查询图片异常",{icon: 5});
            }
        });
    }
    switch(obj.event){
        case 'newfinished':
            parent.intab("views/jsp/ExportBusiness/tpl/newupprocurement.jsp?types=3","新建备货采购");
            break;
        case 'newaccessories':
            parent.intab("views/jsp/ExportBusiness/tpl/newupprocurement.jsp?types=4","新建销售采购");
            break;
        case 'newSamplePurchase':
            parent.intab("views/jsp/ExportBusiness/tpl/newSamplePurchase.jsp?types=5","新建样品采购");
            break;
        case 'prints':
            if(checkStatus.data.length > 1){
                layer.msg("每次只能打印一个采购单!");
                break;
            }
            if(checkStatus.data.length == 0){
                layer.msg("请选择要打印的采购单!");
                break;
            }
            window.open("views/jsp/report.jsp?ym=purchaseReportNew&code=code:"+checkStatus.data[0].id)
            break;
        case 'feedback':
            if(checkStatus.data.length > 1){
                layer.msg( "只能选择一条数据");
                break;
            }
            layer.open({
                type: 2,
                area: ['1488px', '800px'],
                content: 'views/jsp/ExportBusiness/tpl/feedback.jsp?purchaseId='+checkStatus.data[0].id
            });
            break;
    };
});

$("#statistical").on("click",function () {
    parent.intab("views/jsp/ExportBusiness/tpl/statistics.jsp","采购统计");
});


function deleteById(delId) {
    let tf = false;
    $.ajax({
        type: 'POST',
        url: 'purchase/delete/'+delId,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        async: false,
        success: function (res) {
            if (res.status == 200) {
                if(res.data){
                    tf = true;
                    layer.msg("删除成功",{icon: 1});
                    table.reload('procurementtableid');
                }else{
                    layer.msg("删除失败",{icon: 4});
                }
            }else{
                layer.msg("删除失败",{icon: 2});
            }
        },
        error: function (data) {
            layer.msg("删除异常",{icon: 5});
        }
    });
    return tf;
}
//boxStatus 1 草稿 2 待批  3:已批 4 完成 5 垃圾
function updateRemark(id,boxStatus,titleName,remark) {
    let dataJson = {
        "id":id,
        "boxStatus":boxStatus,
        "purchaseBpmId":purchaseBpmId,
        "purchaseBpmStatus":purchaseBpmStatus,
        "remark":remark,
    };
    $.ajax({
        type: 'POST',
        data: JSON.stringify(dataJson),
        url: 'purchase/updateBoxStatusByKey',
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        async: false,
        success: function (da) {
            if (da.status == 200) {
                layer.msg("终止成功",{icon: 6});
                setTimeout(function () {
                    table.reload('procurementtableid');
                    layer.closeAll();
                }, 1000);
            }
        }
    });
}

//boxStatus 1 草稿 2 待批  3:已批 4 完成 5 垃圾
function update(id,boxStatus,titleName) {
    let tf = false;
    let msgInfo = "";
    let dataJson = {
        "id":id,
        "boxStatus":boxStatus,
        "purchaseBpmId":purchaseBpmId,
        "purchaseBpmStatus":purchaseBpmStatus,
    };
    $.ajax({
        type: 'POST',
        data: JSON.stringify(dataJson),
        url: 'purchase/updateBoxStatusByKey',
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        async: false,
        success: function (da) {
            if (da.status == 200) {
                tf = true;
                msgInfo = titleName+"成功!"
                table.reload('procurementtableid');
            }else{
                msgInfo = titleName+"失败!"
            }
        },
        error: function (data) {
            msgInfo = titleName+"异常!"
        }
    });
    layer.msg(msgInfo);
    return tf;
}

function startPurchaseProcess(bid) {
    let res="";
    $.ajax({
        type : 'get',
        data:{"processDefId":'purchase',"bid":bid,"variables":null},
        url:'process/startProcess',
        async:false,
        dataType:"json",
        contentType: "application/x-www-form-urlencoded; charset=utf-8",

        success : function (da) {

            if(da.status==200 ){
                res=da.data;
            }
        },
        error: function(data) {
            // layer.msg("获取失败!");
        }
    });
    return res;
}


function isEmpty(obj){
    if(typeof obj == "undefined" || obj == null || obj == "" || obj == 0){
        return true;
    }else{
        return false;
    }
}
//去除重复对象
function delObj(obj) {
    var uniques = [];
    var stringify = {};
    for (var i = 0; i < obj.length; i++) {
        var keys = Object.keys(obj[i]);
        keys.sort(function(a, b) {
            return (Number(a) - Number(b));
        });
        var str = '';
        for (var j = 0; j < keys.length; j++) {
            str += JSON.stringify(keys[j]);
            str += JSON.stringify(obj[i][keys[j]]);
        }
        if (!stringify.hasOwnProperty(str)) {
            uniques.push(obj[i]);
            stringify[str] = true;
        }
    }
    uniques = uniques;
    return uniques;
}

//提示信息渲染
function confirmInfo(icon, anim) {
    let data = {
        icon: icon,
        title: "提示",
        offset: "auto",
        skin: 'layui-layer-molv',
        anim: anim
    }
    return data;
}

function isNotResearchAndDevelopmentF() {
    $.ajax({
        url: 'purchase/isNotResearchAndDevelopment',
        type: 'GET',
        async: false, // 同步
        success: function (date) {
            isNotResearchAndDevelopment=date.data
        }
    })
}